<!--
 * @Author: Vben
 * @Description: logo component
-->
<template>
  <div class="anticon" v-if="logo" :class="getAppLogoClass" @click="goHome">
    <img :class="`${prefixCls}__img`" style="width: 24px; height: 24px" :src="logo" />
    <div class="ml-1 truncate md:opacity-100" :class="getTitleClass" v-show="showTitle">
      {{ title }}
    </div>
  </div>
</template>
<script lang="ts" setup>
  import { computed, unref } from 'vue';
  // import { useGlobSetting } from '/@/hooks/setting';
  import { useGo } from '/@/hooks/web/usePage';
  import { useMenuSetting } from '/@/hooks/setting/useMenuSetting';
  import { useDesign } from '/@/hooks/web/useDesign';
  import { useDomainStoreWithOut } from '/@/store/modules/domain';
  import { usePermissionStore } from '/@/store/modules/permission';

  const props = defineProps({
    /**
     * The theme of the current parent component
     */
    theme: { type: String, validator: (v: string) => ['light', 'dark'].includes(v) },
    /**
     * Whether to show title
     */
    showTitle: { type: Boolean, default: true },
    /**
     * The title is also displayed when the menu is collapsed
     */
    alwaysShowTitle: { type: Boolean },
    icon: String,
  });

  const { prefixCls } = useDesign('app-logo');
  const { getCollapsedShowTitle } = useMenuSetting();
  const domainStore = useDomainStoreWithOut();
  const permissionStore = usePermissionStore();

  // const { title } = useGlobSetting();
  const title = computed(() => domainStore.getProjectInfo?.title);

  const logo = computed(() => {
    return props.icon ? props.icon : domainStore.getProjectInfo?.logo;
  });

  const go = useGo();

  const getAppLogoClass = computed(() => [
    prefixCls,
    props.theme,
    { 'collapsed-show-title': unref(getCollapsedShowTitle) },
  ]);

  const getTitleClass = computed(() => [
    `${prefixCls}__title`,
    {
      'xs:opacity-0': !props.alwaysShowTitle,
    },
  ]);

  function goHome() {
    const homePath = permissionStore.getFirstMenuParams?.redirect;
    homePath && go(homePath);
  }
</script>
<style lang="less" scoped>
  @font-face {
    font-family: Logo-Title;
    src: url('../../../assets/fonts/Lion-Tail-Leg-Circle-SC-Black.ttf');
  }
  @prefix-cls: ~'@{namespace}-app-logo';

  .truncate {
    font-family: Logo-Title;
  }
  .@{prefix-cls} {
    display: flex;
    align-items: center;
    padding-left: 12px;
    cursor: pointer;
    transition: all 0.2s ease;

    &.light {
      border-bottom: 1px solid @border-color-base;
    }

    &.collapsed-show-title {
      padding-left: 20px;
    }

    &.light &__title {
      color: @primary-color;
    }

    &.dark &__title {
      color: @white;
    }

    &__img {
      width: 24px;
      height: 24px;
    }

    &__title {
      font-size: 18px;
      font-weight: 700;
      transition: all 0.5s;
      line-height: normal;
    }
  }
</style>
